# -*- coding: utf-8 -*-
import requests
def gitIp():
    ipList=[]
    with open("./test4.txt", "r") as f:
        ipList=f.read().split("\n")
    return ipList
ipList='''82.196.3.21:10080
103.21.163.76:6667
103.216.82.200:6667
103.21.163.82:6667
103.216.82.18:6667
103.216.82.19:6667
103.216.82.29:6667
138.197.157.44:1080
149.154.135.6:9999
92.62.72.23:9999'''.split('\n')
def valVer(proxys):
    badNum = 0
    goodNum = 0
    for proxy in proxys:
        try:
            proxy_host = 'socks4://' + proxy
            proxies = {'http': proxy_host,'https':proxy_host}

            response = requests.get('https://www.google.com',
                                    proxies=proxies, timeout=10)
            if response.status_code != 200:
                badNum += 1
                print proxy_host, 'bad proxy'
            else:
                goodNum += 1
                print proxy_host, 'success proxy'
                success = proxy_host + '\n'
                with open ('./success_sokcs4.txt','a+') as f:
                    f.write(success)

        except Exception, e:
            # print e
            print proxy_host, 'bad proxy'
            badNum += 1
            continue
    print 'success proxy num : ', goodNum
    print 'bad proxy num : ', badNum

valVer(gitIp())  #读取本地文件里的IP
# valVer(ipList)
